<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>逻辑中断</title>
</head>

<body>
  <script>
    // 逻辑中断   && ||

    // 1. 逻辑与中断：如果左边为假，则中断，如果左边为真，则返回右边的值
    function sum(x, y) {
      // x = undefined
      //  x = undefined || 0   
      // x = 1 || 0
      x = x || 0
      y = y || 0
      // 对于复杂的代码推荐使用函数里面逻辑中断
      return x + y
    }
    console.log(sum())  // 0
    console.log(sum(1, 2)) // 3


    //
    function getSum(x=0, y=0) {
      return x +y
    } 
    getSum()
  </script>
</body>

</html>